jz()


// 方法区
function jz(){
    layui.use(['form','jquery','upload'],function (){
        var $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#userUrl'
            ,url: '/YltUpload'
            ,accept:'images'
            ,acceptMime:'image/jpg|image/png'
            ,size:50000
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#userUrl').attr('src', result);
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
                var demoText = $('#demoText');
                demoText.html('<span style="color: #4cae4c;">上传成功</span>');

                var fileupload = $(".image");
                fileupload.attr("value",res.data.fullPath);
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        })


        //点击提交修改信息
        form.on('submit(*)',function (d){
            console.log(d.field);
            if (d.field.userSex == '男'){
                d.field.userSex = 1
            }else {
                d.field.userSex = 0
            }
            // 发送ajax
            $.ajax({
                type:'post',
                url:'/YltUser/UserManage/upUser',
                contentType:'application/json',
                data:JSON.stringify(d.field),
                dataType:'json',
                success:function (rs){

                    if (rs.state == 200){
                        //先得到当前iframe层的索引
                        layer.msg("修改用户信息成功",{time: 1500,icon:6},function (){
                            let index = parent.layer.getFrameIndex(window.name);
                            //再执行关闭
                            parent.layer.close(index);
                            //刷新主页面
                            //调用自己写的重载方法
                            parent.sxTable();
                        })

                    }else {
                        layer.msg("修改用户信息失败",{time: 1500,icon:5},function (){
                            let index = parent.layer.getFrameIndex(window.name);
                            //再执行关闭
                            parent.layer.close(index);
                        });
                    }

                },
                error:function (e){
                    console.log(e);
                    console.log("请求失败")
                }
            })


            return false;
        })

        //点击取消关闭
        form.on('submit(qx)',function (d){
            //获取父级弹窗
            let index = parent.layer.getFrameIndex(window.name);
            //再执行关闭
            parent.layer.close(index);
        })
    })
}